const MovieHttp = require("../../utils/MovieHttp")
Page({

  /**
   * 页面的初始数据
   */
  data: {
    hot: [],
    coming: [],
    theaters: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: async function (options) {
    var ResTop = await MovieHttp.getTop250MovieHttp();
    // console.log(ResTop.data.res);
    ResTop.data.res.forEach(item => {
      var {
        rating
      } = item;
      item.star = MovieHttp.handleStar(rating);
    })
    var ResComing = await MovieHttp.getComingSoonMovieHttp();
    console.log(ResComing.data.res);
    ResComing.data.res.forEach(item => {
      var {
        rating
      } = item;
      item.star = MovieHttp.handleStar(rating);
    })
    var ResTheaters = await MovieHttp.getInTheatersMovieHttp();
    console.log(ResTheaters.data.res);
    ResTheaters.data.res.forEach(item => {
      var {
        raiting
      } = item;
      item.rating = raiting
      item.star = MovieHttp.handleStar(raiting);
    })
    this.setData({
      hot: ResTop.data.res.slice(0,3),
      coming: ResComing.data.res.slice(0,3),
      theaters: ResTheaters.data.res.slice(0,3)
    })
  },
  Morehot(){
    var url = `4000/api/movie/top250`;
    wx.navigateTo({
      url: `../movieMore/movieMore?url=${url}`,
    })
    wx.setNavigationBarTitle({
      title: 'Top250',
    })
  },
  Morecoming(){
    var url = `4000/api/movie/comingSoon`;
    wx.navigateTo({
      url: `../movieMore/movieMore?url=${url}`,
    })
    wx.setNavigationBarTitle({
      title: '即将上映',
    })
  },
  Moretheater(){
    var url = `4000/api/movie/inTheaters`;
    wx.navigateTo({
      url: `../movieMore/movieMore?url=${url}`,
    })
    wx.setNavigationBarTitle({
      title: '正在热映',
    })
  },
  Click(e){
    var key = e.detail;
    wx.navigateTo({
      url: `../MovieSearch/MovieSearch?keyword=${key}`,
    })
  },
  onClick(e){
    var {aid} = e.currentTarget.dataset;
    console.log(aid);
    wx.navigateTo({
      url: `../movieDetail/movieDetail?id=${aid}`,
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})